package br.com.virtual.relatorio.model;

import java.util.ArrayList;
import java.util.List;

import br.com.virtual.base.model.VirtualModel;

public class RelatorioPeriodo<T extends VirtualModel> {

	String periodo;
	private Double total;
	private List<T> itens;
	
	public RelatorioPeriodo(String periodo){
		
		this.itens = new ArrayList<T>();
		this.total = 0.0;
		this.periodo = periodo;
	}
	
	public void addItem(T item, Double valor){
		
		this.total += valor;
		this.itens.add(item);
		
	}
	
	
	/*
	 * g & s
	 * */
	public Double getTotal() {
		return total;
	}
	public void setTotal(Double total) {
		this.total = total;
	}
	public String getPeriodo() {
		return periodo;
	}
	public void setPeriodo(String periodo) {
		this.periodo = periodo;
	}
	public List<T> getItens() {
		return itens;
	}
	public void setItens(List<T> itens) {
		this.itens = itens;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((itens == null) ? 0 : itens.hashCode());
		result = prime * result + ((periodo == null) ? 0 : periodo.hashCode());
		result = prime * result + ((total == null) ? 0 : total.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		
		@SuppressWarnings("unchecked")
		RelatorioPeriodo<T> other = (RelatorioPeriodo<T>) obj;
		if (itens == null) {
			if (other.itens != null)
				return false;
		} else if (!itens.equals(other.itens))
			return false;
		if (periodo == null) {
			if (other.periodo != null)
				return false;
		} else if (!periodo.equals(other.periodo))
			return false;
		if (total == null) {
			if (other.total != null)
				return false;
		} else if (!total.equals(other.total))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "RelatorioPeriodo [periodo=" + periodo + ", total=" + total
				+ ", itens=" + itens + "]";
	}

}
